﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.CodeDom;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using BMC.ARSystem;
using System.Collections;


namespace NRemedy.Test
{
    [TestClass]
    public class CodeGenerateMembers
    {
        private bool returnfalse(string fieldName)
        {
            return false;
        }

        private bool returntrue(string fieldName)
        {
            return true;
        }

        [TestMethod]
        public void Test_GenerateRootNamespace_()
        {
            CodeCompileUnit ccu = new CodeCompileUnit();
            GenerateRootNamespace rn = new GenerateRootNamespace();
            rn.Create(ccu);
            Assert.AreEqual<string>(ccu.Namespaces[0].Name, "NRemedy");
            //parameter check
            try
            {
                rn.Create(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: codeCompileUnit");
            }
        }

        [TestMethod]
        public void Test_GenerateImportNamespace_()
        {
            CodeCompileUnit ccu = new CodeCompileUnit();
            ccu.Namespaces.Add(new CodeNamespace("NRemedy"));
            GenerateImportNamespace imn = new GenerateImportNamespace();
            imn.Create(ccu.Namespaces[0]);
            Assert.AreEqual<int>(ccu.Namespaces[0].Imports.Count, 5);
            string[] __namespaceImport = { "System", "System.Text", "System.Collections.Generic", "NRemedy", "BMC.ARSystem" };
            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual<string>(ccu.Namespaces[0].Imports[i].Namespace.ToString(), __namespaceImport[i].ToString());
            }
            //parameter check
            try
            {
                imn.Create(null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: baseNamespace");
            }

        }

        [TestMethod]
        public void Test_GenerateClass_()
        {
            CodeCompileUnit ccu = new CodeCompileUnit();
            ccu.Namespaces.Add(new CodeNamespace("AR.Entity"));
            ccu.Namespaces[0].Imports.Add(new CodeNamespaceImport("System"));
            GenerateClass gc = new GenerateClass();
            GenerateClassAttributeForTest gca = new GenerateClassAttributeForTest();
            gc.Create(ccu.Namespaces[0], "vAppRequest", "ASB_vAppRequest", gca);
            Assert.AreEqual<string>(ccu.Namespaces[0].Types[0].Name.ToString(), "vAppRequest");
            Assert.AreEqual<string>(ccu.Namespaces[0].Types[0].BaseTypes[0].BaseType.ToString(), "ARBaseForm");
            //-----changed by parker,change above code
            //-----since issue Id #9742 【NRemedy】Defect for ARRegularForm
            //-----ARRegularForm should be dropped.
            //-----and the code generation should generate all property
            Assert.AreEqual<string>(ccu.Namespaces[0].Types[0].Attributes.ToString(), "Public");
            //parameter check
            try
            {
                gc.Create(null, "vAppRequest", "ASB_vAppRequest", gca);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: rootNamespace");
            }
            try
            {
                gc.Create(ccu.Namespaces[0], null, "ASB_vAppRequest", gca);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: className");
            }
            try
            {
                gc.Create(ccu.Namespaces[0], "vAppRequest", null, gca);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: formName");
            }
            try
            {
                gc.Create(ccu.Namespaces[0], "vAppRequest", "ASB_vAppRequest", null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributeGenerator");
            }
            try
            {
                gc.Create(ccu.Namespaces[0], "vApp.Request", "ASB_vAppRequest", gca);
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual<string>(e.Message, @"className should not contains '.'");
            }
        }

        [TestMethod]
        public void Test_GenerateField_()
        {
            //if branch
            GenerateField gf = new GenerateField();
            CodeTypeDeclaration classType = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd = new GenerateFieldDelegate(returntrue);
            gf.Create(classType, "_FieldName", typeof(String).Name, "FieldName", gfd);
            Assert.AreEqual<int>(classType.Members.Count, 1);
            Assert.AreEqual<string>(classType.Members[0].Name, "_FieldName");
            Assert.AreEqual<string>(classType.Members[0].Attributes.ToString(), "20482");//20482 mean "MemberAttributes.Private | MemberAttributes.Final"
            CodeMemberField cmf = (CodeMemberField)classType.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "String");
            //else branch
            GenerateField gf2 = new GenerateField();
            CodeTypeDeclaration classType2 = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd2 = new GenerateFieldDelegate(returnfalse);
            gf2.Create(classType2, "_FieldName", typeof(System.String).Name, "FieldName", gfd2);
            Assert.AreEqual<int>(classType2.Members.Count, 0);
            //parameter check
            try
            {
                gf.Create(null, "_FieldName", typeof(System.String).Name, "FieldName", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gf.Create(classType, null, typeof(System.String).Name, "FieldName", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldName");
            }
            try
            {
                gf.Create(classType, "_FieldName", null, "FieldName", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldType");
            }
            try
            {
                gf.Create(classType, "_FieldName", typeof(System.String).Name, null, gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gf.Create(classType, "_FieldName", typeof(System.String).Name, "FieldName", null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldDelegate");
            }
        }

        [TestMethod]
        public void Test_GenerateSelectionField_()
        {
            //if branch
            GenerateSelectionField gf = new GenerateSelectionField();
            CodeTypeDeclaration classType = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd = new GenerateFieldDelegate(returntrue);
            gf.Create(classType, "_SelectionField", "SelectionFieldType", "SelectionField", gfd);
            Assert.AreEqual<int>(classType.Members.Count, 1);
            Assert.AreEqual<string>(classType.Members[0].Name, "_SelectionField");
            Assert.AreEqual<string>(classType.Members[0].Attributes.ToString(), "20482");//20482 mean "MemberAttributes.Private | MemberAttributes.Final"
            CodeMemberField cmf = (CodeMemberField)classType.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "SelectionField_Enum");
            //else branch
            GenerateSelectionField gf2 = new GenerateSelectionField();
            CodeTypeDeclaration classType2 = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd2 = new GenerateFieldDelegate(returnfalse);
            gf2.Create(classType2, "_SelectionField", "SelectionFieldType", "SelectionField", gfd2);
            Assert.AreEqual<int>(classType2.Members.Count, 0);
            //parameter check
            try
            {
                gf.Create(null, "_SelectionField", "SelectionField", "SelectionField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gf.Create(classType, null, "SelectionField", "SelectionField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldName");
            }
            try
            {
                gf.Create(classType, "_SelectionField", null, "SelectionField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldType");
            }
            try
            {
                gf.Create(classType, "_SelectionField", "SelectionField", null, gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gf.Create(classType, "_SelectionField", "SelectionField", "SelectionField", null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldDelegate");
            }
        }

        [TestMethod]
        public void Test_GenerateDiaryField_()
        {
            //if branch
            GenerateDiaryField gf = new GenerateDiaryField();
            CodeTypeDeclaration classType = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd = new GenerateFieldDelegate(returntrue);
            gf.Create(classType, "_DiaryFieldSet", "DiaryFieldType", "DiaryField", gfd);
            Assert.AreEqual<int>(classType.Members.Count, 2);
            Assert.AreEqual<string>(classType.Members[0].Name, "_DiaryFieldSet");
            Assert.AreEqual<string>(classType.Members[0].Attributes.ToString(), "20482");//20482 mean "MemberAttributes.Private | MemberAttributes.Final"
            CodeMemberField cmf = (CodeMemberField)classType.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "String");
            Assert.AreEqual<string>(classType.Members[1].Name, "_DiaryFieldGet");
            Assert.AreEqual<string>(classType.Members[1].Attributes.ToString(), "20482");//20482 mean "MemberAttributes.Private | MemberAttributes.Final"
            CodeMemberField cmf1 = (CodeMemberField)classType.Members[1];
            Assert.AreEqual<string>(cmf1.Type.BaseType.ToString(), "DiaryList");
            //else branch
            GenerateDiaryField gf2 = new GenerateDiaryField();
            CodeTypeDeclaration classType2 = new CodeTypeDeclaration();
            GenerateFieldDelegate gfd2 = new GenerateFieldDelegate(returnfalse);
            gf2.Create(classType2, "_DiaryFieldSet", "DiaryFieldType", "DiaryField", gfd2);
            Assert.AreEqual<int>(classType2.Members.Count, 0);
            //parameter check
            try
            {
                gf.Create(null, "_DiaryFieldSet", "_DiaryFieldGet", "DiaryField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gf.Create(classType, null, "_DiaryFieldGet", "DiaryField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldName");
            }
            try
            {
                gf.Create(classType, "_DiaryFieldSet", null, "DiaryField", gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldType");
            }
            try
            {
                gf.Create(classType, "_DiaryFieldSet", "_DiaryFieldGet", null, gfd);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gf.Create(classType, "_DiaryFieldSet", "_DiaryFieldGet", "DiaryField", null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: fieldDelegate");
            }
        }

        [TestMethod]
        public void Test_GenerateProperty_()
        {
            //if branch
            GenerateProperty gp = new GenerateProperty();
            CodeTypeDeclaration ctd = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd = new GeneratePropertyDelegate(returntrue);
            Dictionary<string, object> mapping = new Dictionary<string, object>();
            Limit limit = null;
            GeneratePropertyAttributeForTest gpa = new GeneratePropertyAttributeForTest();
            gp.Create(ctd, "PropertyName", typeof(String).Name, limit, mapping, gpd, gpa);
            Assert.AreEqual<int>(ctd.Members.Count, 1);
            Assert.AreEqual<string>(ctd.Members[0].Name, "PropertyName");
            Assert.AreEqual<string>(ctd.Members[0].Attributes.ToString(), "24578");//20482 mean "MemberAttributes.Public | MemberAttributes.Final"
            CodeMemberProperty cmf = (CodeMemberProperty)ctd.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "String");
            Assert.AreEqual<int>(cmf.GetStatements.Count, 1);
            Assert.AreEqual<int>(cmf.SetStatements.Count, 2);
            //else branch
            GenerateProperty gp2 = new GenerateProperty();
            CodeTypeDeclaration ctd2 = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd2 = new GeneratePropertyDelegate(returnfalse);
            Dictionary<string, object> mapping2 = new Dictionary<string, object>();
            gp2.Create(ctd2, "PropertyName", typeof(System.String).Name, limit, mapping2, gpd2, gpa);
            Assert.AreEqual<int>(ctd2.Members.Count, 0);
            //parameter check
            try
            {
                gp.Create(null, "PropertyName", typeof(String).Name, limit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gp.Create(ctd, null, typeof(String).Name, limit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gp.Create(ctd, "PropertyName", null, limit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyType");
            }
            try
            {
                gp.Create(ctd, "PropertyName", typeof(String).Name, limit, null, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributePropertyValues");
            }
            try
            {
                gp.Create(ctd, "PropertyName", typeof(String).Name, limit, mapping, null, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyDelegate");
            }
            try
            {
                gp.Create(ctd, "PropertyName", typeof(String).Name, limit, mapping, gpd, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributeGenerator");
            }

        }

        [TestMethod]
        public void Test_CreateSelectionProperty_()
        {
            //if branch
            GenerateSelectionProperty gp = new GenerateSelectionProperty();
            CodeTypeDeclaration ctd = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd = new GeneratePropertyDelegate(returntrue);
            Dictionary<string, object> mapping = new Dictionary<string, object>();
            SelectionLimit selectionLimit = new SelectionLimit();
            ArrayList limitValues = new ArrayList();
            Object[] objects = new Object[2];
            objects[0] = "aa";
            objects[1] = "1";
            limitValues.Add(objects);
            Object[] objects2 = new Object[2];
            objects2[0] = "bb";
            objects2[1] = "2";
            limitValues.Add(objects2);
            selectionLimit.Values = limitValues;
            GeneratePropertyAttributeForTest gpa = new GeneratePropertyAttributeForTest();
            gp.Create(ctd, "PropertyName", "PropertyType", selectionLimit, mapping, gpd, gpa);
            Assert.AreEqual<int>(ctd.Members.Count, 2);
            Assert.AreEqual<string>(ctd.Members[0].Name, "PropertyName");
            Assert.AreEqual<string>(ctd.Members[0].Attributes.ToString(), "24578");//24578 mean "MemberAttributes.Public | MemberAttributes.Final"
            CodeMemberProperty cmf = (CodeMemberProperty)ctd.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "PropertyName_Enum");
            Assert.AreEqual<int>(cmf.GetStatements.Count, 1);
            Assert.AreEqual<int>(cmf.SetStatements.Count, 2);
            Assert.AreEqual<string>(ctd.Members[1].Name, "PropertyName_Enum");
            Assert.AreEqual<string>(ctd.Members[1].Attributes.ToString(), "24578");//24578 mean "MemberAttributes.Public | MemberAttributes.Final"
            CodeTypeDeclaration sctd = (CodeTypeDeclaration)ctd.Members[1];
            Assert.AreEqual<bool>(sctd.IsEnum, true);
            Assert.AreEqual<int>(sctd.Members.Count, 2);
            CodeMemberField ctde0 = (CodeMemberField)sctd.Members[0];
            Assert.AreEqual<string>(ctde0.Name, "aa");
            Assert.AreEqual<string>(((CodeSnippetExpression)ctde0.InitExpression).Value, "1");
            CodeMemberField ctde1 = (CodeMemberField)sctd.Members[1];
            Assert.AreEqual<string>(ctde1.Name, "bb");
            Assert.AreEqual<string>(((CodeSnippetExpression)ctde1.InitExpression).Value, "2");
            //else branch
            GenerateSelectionProperty gp2 = new GenerateSelectionProperty();
            CodeTypeDeclaration ctd2 = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd2 = new GeneratePropertyDelegate(returnfalse);
            Dictionary<string, object> mapping2 = new Dictionary<string, object>();
            gp2.Create(ctd2, "PropertyName", typeof(System.String).Name, selectionLimit, mapping2, gpd2, gpa);
            Assert.AreEqual<int>(ctd2.Members.Count, 0);
            //parameter check
            try
            {
                gp.Create(null, "PropertyName", "PropertyType", selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gp.Create(ctd, null, "PropertyType", selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gp.Create(ctd, "PropertyName", null, selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyType");
            }
            try
            {
                gp.Create(ctd, "PropertyName", "PropertyType", null, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: selectionLimit");
            }
            try
            {
                gp.Create(ctd, "PropertyName", "PropertyType", selectionLimit, null, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributePropertyValues");
            }
            try
            {
                gp.Create(ctd, "PropertyName", "PropertyType", selectionLimit, mapping, null, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyDelegate");
            }
            try
            {
                gp.Create(ctd, "PropertyName", "PropertyType", selectionLimit, mapping, gpd, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributeGenerator");
            }
        }

        [TestMethod]
        public void Test_CreateDiaryProperty_()
        {
            //if branch
            GenerateDiaryProperty gp = new GenerateDiaryProperty();
            CodeTypeDeclaration ctd = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd = new GeneratePropertyDelegate(returntrue);
            Dictionary<string, object> mapping = new Dictionary<string, object>();
            SelectionLimit selectionLimit = new SelectionLimit();
            GeneratePropertyAttributeForTest gpa = new GeneratePropertyAttributeForTest();
            gp.Create(ctd, "DiaryPropertyName", "DiaryPropertyType", selectionLimit, mapping, gpd, gpa);
            Assert.AreEqual<int>(ctd.Members.Count, 2);
            Assert.AreEqual<string>(ctd.Members[0].Name, "DiaryPropertyNameGet");
            Assert.AreEqual<string>(ctd.Members[0].Attributes.ToString(), "24578");//24578 mean "MemberAttributes.Public | MemberAttributes.Final"
            CodeMemberProperty cmf = (CodeMemberProperty)ctd.Members[0];
            Assert.AreEqual<string>(cmf.Type.BaseType.ToString(), "DiaryList");
            Assert.AreEqual<int>(cmf.GetStatements.Count, 1);
            Assert.AreEqual<int>(cmf.SetStatements.Count, 2);
            Assert.AreEqual<string>(ctd.Members[1].Name, "DiaryPropertyNameSet");
            Assert.AreEqual<string>(ctd.Members[1].Attributes.ToString(), "24578");//24578 mean "MemberAttributes.Public | MemberAttributes.Final"
            CodeMemberProperty cmf2 = (CodeMemberProperty)ctd.Members[1];
            Assert.AreEqual<string>(cmf2.Type.BaseType.ToString(), "String");
            Assert.AreEqual<int>(cmf2.GetStatements.Count, 1);
            Assert.AreEqual<int>(cmf2.SetStatements.Count, 2);
            //else branch
            GenerateDiaryProperty gp2 = new GenerateDiaryProperty();
            CodeTypeDeclaration ctd2 = new CodeTypeDeclaration();
            GeneratePropertyDelegate gpd2 = new GeneratePropertyDelegate(returnfalse);
            Dictionary<string, object> mapping2 = new Dictionary<string, object>();
            gp2.Create(ctd2, "PropertyName", typeof(System.String).Name, selectionLimit, mapping2, gpd2, gpa);
            Assert.AreEqual<int>(ctd2.Members.Count, 0);
            //parameter check
            GenerateDiaryProperty gp3 = new GenerateDiaryProperty();
            try
            {
                gp3.Create(null, "PropertyName", "PropertyType", selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: classType");
            }
            try
            {
                gp3.Create(ctd, null, "PropertyType", selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyName");
            }
            try
            {
                gp3.Create(ctd, "PropertyName", null, selectionLimit, mapping, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyType");
            }
            try
            {
                gp3.Create(ctd, "PropertyName", "PropertyType", selectionLimit, null, gpd, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributePropertyValues");
            }
            try
            {
                gp3.Create(ctd, "PropertyName", "PropertyType", selectionLimit, mapping, null, gpa);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: propertyDelegate");
            }
            try
            {
                gp3.Create(ctd, "PropertyName", "PropertyType", selectionLimit, mapping, gpd, null);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributeGenerator");
            }
        }

        [TestMethod]
        public void Test_GenerateAttribute_()
        {
            //if(value.GetType().IsEnum) branch
            CodeTypeMember targetType = new CodeTypeMember();
            Type attributeType = typeof(String);
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add("FormName", "TestForm");
            GenerateAttribute gc = new GenerateAttribute();
            gc.Create(targetType, attributeType, properties);
            Assert.AreEqual<int>(targetType.CustomAttributes.Count, 1);
            Assert.AreEqual<int>(targetType.CustomAttributes[0].Arguments.Count, 1);
            Assert.AreEqual<string>(targetType.CustomAttributes[0].Name, "System.String");
            Assert.AreEqual<string>(targetType.CustomAttributes[0].Arguments[0].Name, "FormName");
            CodePrimitiveExpression cpe = (CodePrimitiveExpression)targetType.CustomAttributes[0].Arguments[0].Value;
            Assert.AreEqual<string>(cpe.Value.ToString(), "TestForm");
            //else branch
            CodeTypeMember targetType2 = new CodeTypeMember();
            Type attributeType2 = typeof(String);
            Dictionary<string, object> properties2 = new Dictionary<string, object>();
            properties2.Add("EnumTest", EnumForTest.bb);
            GenerateAttribute gc2 = new GenerateAttribute();
            gc2.Create(targetType2, attributeType2, properties2);
            Assert.AreEqual<int>(targetType2.CustomAttributes.Count, 1);
            Assert.AreEqual<int>(targetType2.CustomAttributes[0].Arguments.Count, 1);
            Assert.AreEqual<string>(targetType2.CustomAttributes[0].Name, "System.String");
            Assert.AreEqual<string>(targetType2.CustomAttributes[0].Arguments[0].Name, "EnumTest");
            CodePropertyReferenceExpression cpe2 = (CodePropertyReferenceExpression)targetType2.CustomAttributes[0].Arguments[0].Value;
            Assert.AreEqual<string>(cpe2.PropertyName.ToString(), "bb");
            //parameter check
            GenerateAttribute ga3 = new GenerateAttribute();
            try
            {
                ga3.Create(null, attributeType, properties);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: targetType");
            }
            try
            {
                ga3.Create(targetType, null, properties);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual<string>(e.Message, @"Value cannot be null.
Parameter name: attributeType");
            }
        }

        [TestMethod]
        public void Test_GenerateNameResolver_()
        {
            string fieldName = @"\\//11Test:Generate Name%Resolver_100@([+/-^*.&,#])汉字"; //保留字母、数字和下划线
            GenerateNameResolver gnr = new GenerateNameResolver();

            Assert.AreEqual<string>(gnr.DefaultClassNameResolver(fieldName), "_11TestGenerateNameResolver_100");
            Assert.AreEqual<string>(gnr.DefaultFieldNameResolver(fieldName), "__11TestGenerateNameResolver_100");
            Assert.AreEqual<string>(gnr.DefaultPropertyNameResolver(fieldName), "_11TestGenerateNameResolver_100");
            Assert.AreEqual<string>(gnr.SelectionTypeResolver(fieldName), "_11TestGenerateNameResolver_100_Enum");
            Assert.AreEqual<string>(gnr.DiaryFieldNameGetResolver(fieldName), "__11TestGenerateNameResolver_100Get");
            Assert.AreEqual<string>(gnr.DiaryFieldNameSetResolver(fieldName), "__11TestGenerateNameResolver_100Set");
            Assert.AreEqual<string>(gnr.DiaryPropertyNameGetResolver(fieldName), "_11TestGenerateNameResolver_100Get");
            Assert.AreEqual<string>(gnr.DiaryPropertyNameSetResolver(fieldName), "_11TestGenerateNameResolver_100Set");
        }

        [TestMethod]
        public void Test_GetGenerateFieldDelegate_()
        {
            //string[] ARRegularFormpi = { "Request_ID", "Submitter", "Create_Date", "Assigned_To", "Last_Modifed_By", "Modifed_Date", "Status", "Short_Description" };
            //string[] NoARRegularFormpi = { "xxxxxxx", "cChr_Description" };
            //GetGenerateFieldDelegate ggfd = new GetGenerateFieldDelegate();
            //GenerateFieldDelegate gfdDelegateMethod = ggfd.getGenerateFieldDelegate();
            //foreach (var fieldName in ARRegularFormpi)
            //{
            //    Assert.AreEqual<bool>(gfdDelegateMethod(fieldName), false);
            //}
            //foreach (var fieldName in NoARRegularFormpi)
            //{
            //    Assert.AreEqual<bool>(gfdDelegateMethod(fieldName), true);
            //}

            //-----changed by parker,comment above code
            //-----since issue Id #9742 【NRemedy】Defect for ARRegularForm
            //-----ARRegularForm should be dropped.
            //-----and the code generation should generate all property
        }

        [TestMethod]
        public void Test_GetGeneratePropertyDelegate()
        {
            //string[] ARRegularFormpi = { "Request_ID", "Submitter", "Create_Date", "Assigned_To", "Last_Modifed_By", "Modifed_Date", "Status", "Short_Description" };
            //string[] NoARRegularFormpi = { "xxxxxxx", "cChr_Description" };
            //GetGeneratePropertyDelegate ggpd = new GetGeneratePropertyDelegate();
            //GeneratePropertyDelegate ggpDelegateMethod = ggpd.getGeneratePropertyDelegate();
            //foreach (var propertyName in ARRegularFormpi)
            //{
            //    Assert.AreEqual<bool>(ggpDelegateMethod(propertyName), false);
            //}
            //foreach (var propertyName in NoARRegularFormpi)
            //{
            //    Assert.AreEqual<bool>(ggpDelegateMethod(propertyName), true);
            //}

            //-----changed by parker,comment above code
            //-----since issue Id #9742 【NRemedy】Defect for ARRegularForm
            //-----ARRegularForm should be dropped.
            //-----and the code generation should generate all property
        }

        [TestMethod]
        public void Test_ARSelectionTypeConvert_()
        {
            ArrayList limitValues = new ArrayList();
            Object[] objects = new Object[2];
            objects[0] = "\\//22a a";
            objects[1] = "1";
            limitValues.Add(objects);
            Object[] objects2 = new Object[2];
            objects2[0] = "\\//22b _b ";
            objects2[1] = "2";
            limitValues.Add(objects2);
            ARSelectionType selection = ARSelectionTypeConvert.GetSelection(limitValues);
            Assert.AreEqual<string>(selection.item[0].value, "_22aa");
            Assert.AreEqual<string>(selection.item[1].value, "_22b_b");
        }

    }

    internal class GenerateClassAttributeForTest : IGenerateClassAttribute
    {
        public void Create(CodeTypeDeclaration classType, Type attributeType, Dictionary<string, object> properties)
        {
            return;
        }
    }

    internal class GeneratePropertyAttributeForTest : IGeneratePropertyAttribute
    {
        public void Create(CodeMemberProperty propertyType, Type attributeType, Dictionary<string, object> properties)
        {
            return;
        }
    }

    internal enum EnumForTest : uint
    {
        aa = 0u,
        bb = 1u,
    }

}
